import requests

from api.open_account_api import OpenAccount
from api.reg_login_api import RegLoginApi
from common.assert_tools import common_assert
from common.read_html_tools import html_util


class TestOpenAccount(object):

    def setup(self):
        # 创建session对象
        self.ses = requests.session()
        # 实例化封装接口请求的类
        self.reg_login = RegLoginApi(self.ses)
        self.open_account = OpenAccount(self.ses)


    def teardown(self):
        # 关闭session对象
        self.ses.close()

    # 实名认证测试用例
    def test01_realname(self):
        # 实现登录接口
        self.reg_login.user_login("13155552220", "qq1234")
        # 实现实名认证接口
        resp = self.open_account.realname("张三", "430802199003075874")
        # 断言
        common_assert(resp, 200, 200, "成功")

    # 开户测试用例
    def test02_open_account(self):
        # 实现登录接口
        self.reg_login.user_login("13155552220", "qq1234")
        # 实现开户接口
        resp = self.open_account.open_account()
        # 断言
        common_assert(resp, 200, 200, "form")

    # 第三方开户测试用例
    def test03_third_open_account(self):
        # 实现登录接口
        self.reg_login.user_login("13155552220", "qq1234")
        # 实现开户接口
        resp_open_account = self.open_account.open_account()
        result = html_util(resp_open_account)
        url = result[0]
        form_dict = result[1]
        # 实现第三方开户接口
        resp = self.open_account.third_open_account(url, form_dict)
        # 断言
        assert 200 == resp.status_code
        assert "OK" in resp.text
